package com.ioc.config;


import com.ioc.dao.UserDao;
import com.ioc.factorybean.ColorFactory;
import com.ioc.importselector.BeanDefinitionRegistrar;
import com.ioc.importselector.Selector;
import com.ioc.pojo.User;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created by win10 on 2020/2/8 13:52
 */
@Configuration
//配置类
@ComponentScan(basePackages = "com.ioc")
// 组件扫描
@Component
// 配置bean
@PropertySource(value = "classpath:cyt.properties")
// 指定配置文件位置
@Import({Selector.class, BeanDefinitionRegistrar.class})
public class Beanfig {
    @Bean
    public ColorFactory colorFactory() {
        return new ColorFactory();
    }
    @Bean
    public UserDao getUserDao() {
        return new UserDao();
    }

    /**
     * @return
     * @Scope("prototype") 使用注解为 bean 指定 id、 以及 作用范围
     */
    @Bean("user")
    public User getUser() {
        System.out.println(
                "创建 user bean "
        );
        return new User();
    }
    @Bean("cyt")
    public User cyt() {
        return new User();
    }
    @Bean("yh")
    public User yh() {
        return new User();
    }
}
